<?php

class imgUpload

{

	/**

	 * @author Jitendra Zaa

	 * @param $imgFolder - Folder for Original Image

	 * @param $thmbFolder - Folder For thumb Image

	 * @param $basePath - Base Path of the client Image

	 * @param $relativePath - Relative Path of the client Image

	 * @param $imgName - Image Name, it will be username mostly

	 * @return Full path of image

	 */

	function createImage($imgFolder,$thmbFolder,$basePath,$userfile_name,$userfile_tmp,$userfile_size,$userfile_type,$imgName){

		$uploadfile = $imgFolder.$basePath;



		if(move_uploaded_file($userfile_tmp, $uploadfile)) {

			

		} 



		$filename = $basePath;

		$file_ext = strtolower(substr($filename, strrpos($filename, '.') + 1));

		$extn = "";

		// Create an Image from it so we can do the resize

		//$src = imagecreatefromjpeg($uploadfile);

		switch($userfile_type) {

			case "image/gif":

				$src=imagecreatefromgif($uploadfile);

				$extn = ".gif";

				break;

			case "image/pjpeg":

			case "image/jpeg":

			case "image/jpg":

				$src=imagecreatefromjpeg($uploadfile);

				$extn = ".jpg";

				break;

			case "image/png":

			case "image/x-png":

				$src=imagecreatefrompng($uploadfile);

				$extn = ".png";

				break;

		}





		list($width,$height)=getimagesize($uploadfile);

		$newwidth=200;

		$newheight=200;

		$newImage=imagecreatetruecolor($newwidth,$newheight);



		// this line actually does the image resizing, copying from the original

		// image into the $tmp image

		//bool imagecopyresampled ( resource $dst_image , resource $src_image , int $dst_x , int $dst_y , int $src_x , int $src_y , int $dst_w , int $dst_h , int $src_w , int $src_h )

		imagecopyresampled($newImage,$src,0,0,0,0,$newwidth,$newheight,$width,$height);



		// now write the resized image to disk. I have assumed that you want the

		// resized, uploaded image file to reside in the ./images subdirectory.

		$filename = $thmbFolder.$imgName.$extn;



		switch($userfile_type) {

			case "image/gif":

				imagegif($newImage,$filename);

				break;

			case "image/pjpeg":

			case "image/jpeg":

			case "image/jpg":

				imagejpeg($newImage,$filename,90);

				break;

			case "image/png":

			case "image/x-png":

				imagepng($newImage,$filename);

				break;

		}

		chmod($filename, 0777);

		return $filename;

	}

}

?>